package com.tanhua.server.exception;

import com.tanhua.model.vo.ErrorResult;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class ExceptionAdvice {


    @ExceptionHandler(value = Exception.class)
    public ResponseEntity handlerException(Exception e){
        e.printStackTrace();
        // 通过业务异常对象的方法 返回错误信息
        ErrorResult result = ErrorResult.result();
        return ResponseEntity.status(500).body(result);
    }

    @ExceptionHandler(value = BusinessException.class)
    public ResponseEntity handlerException(BusinessException e){
        e.printStackTrace();
        // 通过业务异常对象的方法 返回错误信息
        ErrorResult result = e.getResult();
        return ResponseEntity.status(500).body(result);

    }





}
